package indi.gao.redis;

import java.io.File;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2019$</p>
 * <p>Company: Tope</p>
 * <P>Created Date :2019$-08$-26$</P>
 * <P>@version 1.0</P>
 * todo 将图片文件的名字改成上层文件夹的名字
 */
public class DirOperate {
    public static void main(String[] args) {
        String picDir = "F:\\workSpace\\UtilTest\\DirOperate\\src\\main\\resources\\images";
        File file = new File(picDir);
        //得到文件夹下的文件夹的名字
        String[] dirNames = file.list();
        assert dirNames != null;
        for (String dirName : dirNames) {
//          图片文件父层文件夹名字
            String picParentDirAbsoluteName = picDir + "\\" + dirName;
            //得到图片的名字
            File file1 = new File(picParentDirAbsoluteName);
            String[] strings = file1.list();
            //得到图片的绝对路径
            assert strings != null;
            String picAbsolute = picParentDirAbsoluteName + "\\" + strings[0];
            File picFile = new File(picAbsolute);
//            替换文件名是要是用绝对路径替换
            Boolean flag = picFile.renameTo(new File(picParentDirAbsoluteName + "\\" + dirName + ".jpg"));
            if (flag) {
                System.out.println("转换成了");
            } else {
                System.out.println("转换失败了");
            }
        }
    }
}
